---@diagnostic disable: undefined-global, lowercase-global, deprecated
module(...,package.seeall)

require "ILI9806E"
require "msg2238"
require "lvsym"
require "ntp"
require "misc"
require "idle"
require "main_Widgets"
require "Multi-Widgets"
require "Single_Widgets"
require "Clock"
require "Floder"

local data = {type = lvgl.INDEV_TYPE_POINTER}

local function input()
    pmd.sleep(100)
    local ret,ispress,px,py = msg2238.get();

    if ret then
        if lastispress == ispress and lastpx == px and lastpy == py then
            --log.info("lvgl input needind false")
            --log.info("lvgl input", ispress,px,py, lastispress,lastpx,lastpy)
            --log.info("lvgl  1 input ispress x,y ",data.state,data.point.x,data.point.y)
            return data
        else
            --log.info("lvgl input", ispress,px,py, lastispress,lastpx,lastpy)
            --log.info("lvgl input needind true")
        end

        lastispress = ispress
        lastpx = px
        lastpy = py

        if ispress then
            tpstate = lvgl.INDEV_STATE_PR
        else
            tpstate = lvgl.INDEV_STATE_REL
        end
    else
        --log.info("lvgl  2 input ispress x,y ",data.state,data.point.x,data.point.y)
        return data;
    end

    local topoint = {x = px,y = py}
    --log.info("lvgl input ispress,px,py ",ispress,px,py)
    data.state = tpstate
    data.point = topoint

    --log.info("input ispress x,y ",data.state,data.point.x,data.point.y)
    return data
end

--iCool手机总界面处理函数
function mainInit()

	--主界面初始化(演示其他Demo时必须添加此函数)
	--Idle_Init()

	--main_WidgetsInit()
    --Multi_WidgetsInit()
    --Single_WidgetsInit()
    iCoolTimeInit()
    --floderInit()


end

local function tp_lvgl()
    log.info("tp_lvgl")
    msg2238.init()
    lvgl.init(mainInit, input)
    -- sys.wait(1000)
end

sys.taskInit(tp_lvgl, nil)